package com.dayu.web.controller.recovery.data;

import com.dayu.common.annotation.Log;
import com.dayu.common.core.controller.BaseController;
import com.dayu.common.core.domain.AjaxResult;
import com.dayu.common.core.page.TableDataInfo;
import com.dayu.common.utils.poi.ExcelUtil;
import com.dayu.recovery.domain.data.GoodsTimeData;
import com.dayu.recovery.service.data.GoodsTimeDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/goods/time")
public class GoodsTimeDataController extends BaseController {

    @Autowired
    private GoodsTimeDataService goodsTimeDataService;

    /** 商品时间列表*/
    @GetMapping("/list")
    public TableDataInfo list(GoodsTimeData timeData) {
        List<GoodsTimeData> list = goodsTimeDataService.list(timeData);
        return getDataTable(list);
    }

    /** 去重复数据列表*/
    @GetMapping("/only/list")
    public TableDataInfo onlyList(GoodsTimeData timeData) {
        return getDataTable(goodsTimeDataService.onlyList(timeData));
    }

    /** 数据导出*/
    @GetMapping("/export")
    public AjaxResult export(GoodsTimeData timeData) {
        if(timeData.getParams() == null) {
            return error();
        }
        List<GoodsTimeData> list = goodsTimeDataService.onlyList(timeData);
        list.forEach(GoodsTimeData::tranString);
        ExcelUtil<GoodsTimeData> util = new ExcelUtil<>(GoodsTimeData.class);
        return util.exportExcel(list,"时效表");
    }
}
